﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Command;
using Framework.Sample.Command.AccountCommands;
using Framework.Infrastructure;
using Framework.Sample.Domain.Model;
using Microsoft.Practices.Unity;
using Framework.UnitOfWork;
using Framework.Bus.NServiceBus;

namespace Framework.CommandHandlers
{
    public class AccountComandHandlers : CommandHandler
    {
        [CommandHandler]
        public void RegisterAccountHandler(RegisterAccount cmd)
        {
            Account account = new Account();
            account.Register("Ivan", 30);
            DomainRepository.Add(account);
            UnitOfWork.Commit();
            cmd.Response = account;
        }

        [CommandHandler]
        public void ChangePasswordHandler(ChangePassword cmd)
        {
            Account account = DomainRepository.GetByKey<Account>(cmd.AccountID);
            account.ChangePassword(cmd.Password);
            UnitOfWork.Commit();
            //this.Reply(new {Success = true, Msg = account.Password });
        }
    }
}
